<template>
  <div class="app">
    <div class="block">
         <h3>猜你喜欢</h3>
        <div class="sortbox">
            <div class="sortList"  @click="sort(index)" :class="{active:currentIndex==index}" v-for="(item,index) in sortList" :key="index">{{item}}</div>
        </div>

        <div class="dvbox">
            <div class="dvList" v-for="(item,index) in dvList" :key="index">{{item}}</div>
        </div>

        <div class="list" v-for="(item,index) in shopList" :key="index">
            <img :src="item.picUrl" alt="">
            <div class="text" >
                <h3>{{item.name}}</h3>
                <p><span>{{item.wmPoiScore}}</span> <span>{{item.monthSalesTip}}</span></p>
                <div class="Tip">
                  <p><span>{{item.minPriceTip}}</span> <span>{{item.shippingFeeTip}}</span></p>

                  <p><span>{{item.deliveryTimeTip}}</span> <span>{{item.distance}}</span></p>
                </div>
                <div class="discounts2"> <span v-for="(item,index) in item.discounts2" :key="index">{{item.info}}</span></div>
          
          </div>
        </div>
    </div>
   
  </div>
</template>

<script>
import {shop_list } from "../Utils/api"
export default {
    data(){
        return{
            currentIndex:0,
            sortList:["综合排序","距离最近","销量最高","筛选"],
            dvList:["年赁节热卖","津贴联盟","满减优惠","品质联盟"],
            shopList:[]
        }
    },
    mounted(){
        shop_list().then((res)=>{
            this.shopList=res.data.list
            console.log( this.shopList)
        })
    },
    methods:{
        sort(index){
            this.currentIndex=index;
            if(index==0){
                this.shopList.sort(function(a,b){
                   return b.wmPoiScore-a.wmPoiScore
                })
            }else if(index==1){
                this.shopList.sort(function(a,b){
                    b=b.distance.match(/(\d+\.)?\d+/g)
                    a=a.distance.match(/(\d+\.)?\d+/g)
                   return b-a
                })
            }else if(index==2){
                this.shopList.sort(function(a,b){
                    b=b.monthSalesTip.match(/(\d+\.)?\d+/g)
                    a=a.monthSalesTip.match(/(\d+\.)?\d+/g)
                   return b-a
                })
            }
           
        }
    }
}
</script>

<style scoped>
.block{
    box-sizing: border-box;
    padding: 10px;
}
/* h3{
   margin-top: 20px;
} */
.sortbox,
.dvbox{
    display: flex;
    justify-content: space-between;
}
.sortList{
    margin-top: 20px;
}
.dvList{
    padding: 5px 8px;
    background-color: #bfbdbd;
    margin-right: 3px;
    margin-top: 20px;
    margin-bottom: 20px;
}
.list {
    display: flex;
    margin-bottom: 20px;
}
.list img{
    width: 100px;
    height: 100px;
    margin-right: 10px;
}
.list .text{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
/* .list p{
    font-size: 14px;
} */
.list p span:first-child{
    color: orange;
}
.list p span:last-child{
    color: gray;
}
.Tip{
    width: 100%;
    display: flex;
    justify-content: space-between;
}
.discounts2 span{
    display: inline-block;
    border: 1px solid hotpink;
    color: hotpink;
    margin-right: 3px;
    font-size: 12px;
}
</style>